﻿using JobBack.Models;
using QG.JobBack.BLL.Service;
using QG.JobBack.DAL;
using QH.JobBack.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace JobBack.Controllers
{
        /// <summary>
        /// 分类管理页面
        /// </summary>
        /// <returns></returns>
        
    public class TypeController : Controller
    {
        PostNameService postNameService = new PostNameService();
        IndustryService industryService = new IndustryService();
        ManagerService managerService = new ManagerService();
        Opretation opretation = new Opretation();
        /// <summary>
        /// 添加职位信息
        /// </summary>
        /// <returns></returns>
        public ActionResult TypeAddManager()
        {
            ViewBag.list=managerService.QueryList(a=>a.LEVEL==1);
            return View();
        }

        /// <summary>
        /// 职位名称信息
        /// </summary>
        /// <returns></returns>
        public ActionResult TypepostName(string Bugeikang)
        {
            Session["Bugeikang"] = Bugeikang;
            return View();
        }
        /// <summary>
        /// 显示职业名称信息
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        public JsonResult QueryPostNameList(int page, int limit)
        {
                PostName postName = new PostName();
            int ass = Convert.ToInt32(Session["Bugeikang"]);
            if (ass!=0)
            {
                postName.ClassId = ass;
            }
            int count = 0;
            List<PostName> menus = postNameService.QueryPageList(page, limit, a => a.ClassId == postName.ClassId, a => a.PostNameId);

            ResponseResult<PostName> getJson = new ResponseResult<PostName>()
            {
                msg = "",
                code = 0,
                count = postNameService.GetCount(a => a.PostNameId != 0, out count),
                data = menus
            };
            return Json(getJson, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 修改职业名称状态
        /// </summary>
        /// <param name="postName"></param>
        /// <returns></returns>
        public JsonResult UpdatePostNameStar(PostName postName)
        {
            opretation.Success = postNameService.UpdateStatus(postName);
            return Json(opretation);
        }

        /// <summary>
        /// 职业分类
        /// </summary>
        /// <returns></returns>
        public ActionResult TypeManager()
        {
            return View();
        }

        /// <summary>
        /// 获取职业列表
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        public JsonResult QueryManagerList(int page, int limit,string Managerid,string ClassName)
        {
            int count = 0;
            List<Classifyinfo> menus = null;
            if (Convert.ToInt32(Managerid) != 0 && ClassName==null)
            {
                Classifyinfo classifyinfos = new Classifyinfo();
                classifyinfos.ParentId = Convert.ToInt32(Managerid);
                menus = managerService.QueryPageList(page, limit, a => a.ParentId == classifyinfos.ParentId, a => a.ClassId);
            }else if (ClassName!=null && Convert.ToInt32(Managerid) == 0)
            {
                menus = managerService.QueryPageList(page, limit, a => a.ClassName.Contains(ClassName), a => a.ClassId);
            }
            else
            {
                menus = managerService.QueryPageList(page, limit, a => a.ParentId == 0,a => a.ClassId);
            }
            ResponseResult<Classifyinfo> getJson = new ResponseResult<Classifyinfo>()
            {
                msg = "",
                code = 0,
                count = managerService.GetCount(a => a.ClassId != 0, out count),
                data = menus
            };
            return Json(getJson, JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 添加职位信息
        /// </summary>
        /// <returns></returns>
        public JsonResult AddManager(Classifyinfo classifyinfo)
        {
            Initialletter initialletter = new Initialletter();
            classifyinfo.Initial = initialletter.GetSpellCode(classifyinfo.ClassName);
            opretation.Success = managerService.AddManagers(classifyinfo);
            return Json(opretation);
        }

        /// <summary>
        /// 修改职位状态
        /// </summary>
        /// <param name="classifyinfo"></param>
        /// <returns></returns>
        public JsonResult UpdateManagerStar(Classifyinfo classifyinfo)
        {
            opretation.Success = managerService.UpdateStatus(classifyinfo);
            return Json(opretation);
        }
        /// <summary>
        /// 删除职位
        /// </summary>
        /// <param name="classifyinfo"></param>
        /// <returns></returns>
        public JsonResult DeleteManager(Classifyinfo classifyinfo)
        {
            opretation.Success = managerService.Delete(classifyinfo);
            return Json(opretation);
        }

        /// <summary>
        /// 添加行业信息
        /// </summary>
        /// <returns></returns>
        public ActionResult TypeAddIndustry(string Nolook = null)
        {
            if (Nolook != null)
            {
                Industry industry = new Industry();
                industry.IndustryId = Convert.ToInt32(Nolook);
                ViewBag.list=industryService.QueryList(a=>a.IndustryId== industry.IndustryId);
            }
            return View();
        }

        /// <summary>
        /// 行业分类
        /// </summary>
        /// <returns></returns>
        public ActionResult TypeIndustry()
        {
            return View();
        }
        /// <summary>
        /// 获取行业列表
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        public JsonResult QueryIndustryList(int page, int limit, string Industryname)
        {
            if (Industryname == null)
            {
                Industryname = "";
            }
            int count = 0;
            List<Industry> menus = industryService.QueryPageList(page, limit, a=>a.IndustryName.Contains(Industryname), a => a.IndustryId);

            ResponseResult<Industry> getJson = new ResponseResult<Industry>()
            {
                msg = "",
                code = 0,
                count = industryService.GetCount(a => a.IndustryId != 0, out count),
                data = menus
            };
            return Json(getJson, JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 新增行业信息
        /// </summary>
        /// <param name="industry"></param>
        /// <returns></returns>
        public JsonResult AddIndustry(Industry industry)
        {
            opretation.Success = industryService.AddIndustrys(industry);
            return Json(opretation);
        }
        /// <summary>
        /// 修改状态
        /// </summary>
        /// <param name="industry"></param>
        /// <returns></returns>
        public JsonResult UpdateStar(Industry industry)
        {
            opretation.Success = industryService.UpdateStatus(industry);
            return Json(opretation);
        }
        /// <summary>
        /// 删除行业信息
        /// </summary>
        /// <param name="industry"></param>
        /// <returns></returns>
        public JsonResult DeleteIndustry(Industry industry)
        {
            opretation.Success = industryService.Delete(industry);
            return Json(opretation);
        }
        /// <summary>
        /// 修改行业信息
        /// </summary>
        /// <param name="industry"></param>
        /// <returns></returns>
        public JsonResult UpdateIndustry(Industry industry)
        {
            opretation.Success = industryService.UpdateIndustry(industry);
            return Json(opretation);
        }
    }
}